package ys

import (
	"encoding/json"
	"fmt"
	"net/url"
)

// 向萤石云发送请求
func (c *Client) doPostForm(relativeUrl string, bodyObj interface{}) (bytes []byte, err error) {
	// 转换参数
	var body map[string]interface{}
	bodyStr, err := json.Marshal(bodyObj)
	if err != nil {
		return
	}
	if err = json.Unmarshal(bodyStr, &body); err != nil {
		return
	}
	formBody := make(url.Values)
	for k, v := range body {
		formBody.Add(k, fmt.Sprintf("%v", v))
	}
	// 发起请求
	bytes, err = httpPostForm(c.url(relativeUrl), formBody)
	return
}
